home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Text / Edit / MegaEd.lha / Trans / MCPP.trans.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-21  |  1.9 KB  |  105 lines

  1. /*
  2. ** MCPP.trans: Konvertiert Maxon C Fehlerdateien für MegaEd
  3. ** von M-J, 100% PD
  4. */
  5.  
  6. #include <exec/memory.h>
  7. #include <dos/dos.h>
  8. #include <dos/dostags.h>
  9. #include <string.h>
  10.  
  11. void main(void)
  12. {
  13.  const char *file1="T:MegaEdMake-ErrFile";
  14.  const char *file2="T:MegaEdMake-Errors";
  15.  BPTR con;
  16.  BPTR fileh;
  17.  char *old=NULL,*new=NULL;
  18.  char *off, *off2, *dest, *warn, *last;
  19.  LONG len;
  20.  short i;
  21.  BOOL errors=FALSE;
  22.                              //MCPP Datei lesen
  23.  if(!(fileh=Open(file1,MODE_OLDFILE))) return;
  24.  Seek(fileh,0,OFFSET_END);
  25.  len=Seek(fileh,0,OFFSET_BEGINNING);
  26.  if(len)
  27.  {
  28.   if(!(old=(char*)AllocVec(len+1,MEMF_PUBLIC)))
  29.    {Close(fileh); return;}
  30.   if(Read(fileh,old,len)!=len)
  31.    {FreeVec(old); Close(fileh); return;}
  32.  }
  33.  Close(fileh);
  34.  if(!len) return;
  35.  old[len]=0;
  36.                             // Konvertierung
  37.  if(!(new=(char*)AllocVec(len+1,MEMF_PUBLIC))) return;
  38.  
  39.  off=old;
  40.  dest=new;
  41.  for(i=0;i<3;i++)    // 3 Zeilen überlesen
  42.  {
  43.   if(!(off=strchr(off,10))) goto esc;
  44.   off++;
  45.  }
  46.  for(;;)
  47.  {
  48.   warn=dest;
  49.   dest++;
  50.   if(!(off2=strchr(off,10))) break;
  51.   *off2=0;
  52.   if(!(off=strchr(off,','))) break;
  53.   off++;
  54.   if(!(off2=strrchr(off,','))) break;
  55.   *off2=0;
  56.   for(;*off;off++)    // Zeile
  57.    if(isdigit(*off)) break;
  58.   if(!*off) break;
  59.   for(;isdigit(*off);off++,dest++) *dest=*off;
  60.   off+=strlen(off)+1;
  61.   *dest='/';
  62.   dest++;
  63.  
  64.   for(;*off;off++)    // Spalte
  65.    if(isdigit(*off)) break;
  66.   if(!*off) break;
  67.   for(;isdigit(*off);off++,dest++) *dest=*off;
  68.   off+=strlen(off)+1;
  69.   *dest=10;
  70.   dest++;
  71.  
  72.             // Text
  73.   if(!(off2=strchr(off,10)))
  74.    off2=strchr(off,0);
  75.   *off2=0;
  76.   strcpy(dest,off);
  77.  
  78.   errors=TRUE;
  79.   if(strncmp(off,"Warn",4)) *warn='E';
  80.   else *warn='W';
  81.  
  82.   off+=strlen(off)+1;
  83.   dest+=strlen(dest);
  84.   *dest=10;
  85.   dest++;
  86.   last=dest;
  87.  
  88.   if(!*off) break;
  89.  }
  90.  esc:
  91.  if(errors)
  92.  {
  93.   if(fileh=Open(file2,MODE_NEWFILE))
  94.   {
  95.    len=(LONG)last-(LONG)new;
  96.    Write(fileh,new,len);
  97.    Close(fileh);
  98.   }
  99.  }
  100.  else DeleteFile(file2);
  101.  if(old) FreeVec(old);
  102.  if(new) FreeVec(new);
  103. }
  104.  
  105.